home *** CD-ROM | disk | FTP | other *** search
/ Nautilus 1994 April / Nautilus CD Magazine Volume 4-4 April 1994 Windows Edition.mdf / setup / nautcd / link / phone.scr < prev    next >
Text File  |  1993-08-18  |  5KB  |  235 lines

  1. !
  2. !  Copyright (c) 1993
  3. !  by CompuServe Incorporated, Columbus, Ohio
  4. !
  5. !  The information in this software is subject to change without
  6. !  notice and should not be construed as a commitment by CompuServe.
  7. !
  8. !  PHONE:
  9. !    Contains modem/phone related logic.
  10. !    Success:  returns %Success
  11. !    Failure:  saves error msg in %FailureMsg and returns %Failure
  12. !
  13. !+V
  14. ! "3.1"
  15. !-V
  16.  
  17. if %DialType = 2 goto Direct_Connect;
  18.  
  19. WaitTime = 10;
  20. ifndef %mdm_UserID = "";
  21. ifndef %mdm_Password = "";
  22.  
  23. goto Do_Phone_Connect;
  24.  
  25. !
  26. ! Subroutines
  27. !
  28. Send_Modem_Cmd:
  29.     sendm %mdm_Prefix;
  30.     sendm ModemStr;
  31.     sendm %mdm_Suffix;
  32. End_Modem_Cmd:
  33.     return;
  34.  
  35.  
  36. Hangup_Before_Connect:
  37.     define %LOCAL = 2;
  38.     call %Dir & "disconct.scr" () : Result;
  39.     return;
  40.  
  41. Two_Tries_Hangup:
  42.     gosub Hangup_Before_Connect;
  43.     goto Send_Reset_String;
  44.  
  45.  
  46. !
  47. ! Main Program:  Start_Connect
  48. !
  49. Do_Phone_Connect:
  50.     RingLimit = 5;
  51.     RingCount = 0;
  52.     UsingModem = %FALSE;
  53.     on cancel goto Phone_Cancelled;
  54.  
  55.     if %DialType = 0 goto Get_Tone_Str;
  56.     DialTypeStr = %mdm_Pulse_Dial;        ! Type = DT_Pulse
  57.     goto Init_Modem;
  58.  
  59. Get_Tone_Str:
  60.     DialTypeStr = %mdm_Tone_Dial;        ! Type = DT_Tone
  61.  
  62. Init_Modem:
  63.     show "Initializing modem";
  64.     MsgStr = "Dialing " & %Phone;
  65.     tries = 0;
  66.  
  67. Send_Reset_String:
  68.     if (%mdm_Reset = "") goto Modem_OK;
  69.     ModemStr = %mdm_Reset;
  70.     gosub Send_Modem_Cmd;
  71.  
  72. Send_Wait:
  73.     wait
  74.         "User Id"    goto Send_User_ID,
  75.         "Password"    goto Send_Password,
  76.         %mdm_Ack    goto Modem_OK,
  77.         "0"        goto Modem_OK
  78.     until 40;
  79.  
  80.     tries = tries + 1;
  81.     if tries = 2 goto Two_Tries_Hangup;    ! Two failures to send Reset -
  82.                         ! hang up and try twice more.
  83.     if tries < 4 goto Send_Reset_String;
  84.  
  85.     wait until WaitTime;
  86.  
  87.     FailStr = "Modem not responding";
  88.     goto Phone_Failed;
  89.  
  90. Send_User_ID:
  91.     !
  92.     ! For those modems that support password security...
  93.     !
  94.     send %mdm_UserID & "^M";
  95.     goto Send_Wait;
  96.  
  97. Send_Password:
  98.     !
  99.     ! For those modems that support password security...
  100.     !
  101.     send %mdm_Password & "^M";
  102.     wait
  103.         "User id"    goto Modem_Security_Error,
  104.         %mdm_Ack    goto Send_Reset_String,
  105.         "0"        goto Send_Reset_String
  106.     until 100;
  107.     goto Send_Reset_String;
  108.  
  109. Modem_Security_Error:
  110.     define %FailureMsg = "Invalid modem security User ID or password";
  111.     exit %Fatal;
  112.  
  113. Modem_OK:
  114.     wait until 10;
  115.     if (%mdm_Init = "") goto Check_Modem_Speaker;
  116.     sendm %mdm_Init;
  117.  
  118.     wait
  119.         %mdm_Ack    goto End_Wait1,
  120.         "ERROR"        goto Show_Error
  121.     until 33;
  122.     goto End_Wait1;
  123.  
  124. Show_Error:
  125.     show "Error in modem initialization command";
  126.     wait until 10;
  127.  
  128. End_Wait1:
  129.  
  130.     wait until 10;
  131.  
  132. Check_Modem_Speaker:
  133.     if (%mdm_Speaker <> 0) goto Try_Phone;
  134.  
  135.     sendm %mdm_Prefix;
  136.     sendm "M0";
  137.     send %CR;
  138.  
  139.     wait
  140.         %mdm_Ack    goto End_Wait2
  141.     until 33;
  142. End_Wait2:
  143.     wait until 10;
  144. Try_Phone:
  145.     count = 0;
  146.     FailStr = "";
  147. Dial_Phone:
  148.     if (count > %Retry) goto Phone_Failed;
  149.  
  150.     show MsgStr;
  151.     ModemStr = DialTypeStr & %Phone;
  152.     gosub Send_Modem_Cmd;
  153.  
  154. Start_Phone_Loop:
  155.     wait
  156.         %mdm_Success    goto Modem_Success,
  157.         %mdm_Failure    goto Modem_Failure,
  158.         "No Dial"    goto No_Dial_Tone,
  159.         "Dial Complete" goto Dial_Complete,
  160.         "Busy"        goto Line_Busy,
  161.         "Ring"        goto Remote_Ring
  162.     until 556;
  163.  
  164.     FailStr = "Dialing failed";
  165.     goto Exit_Failure;
  166.  
  167. Modem_Success:
  168.     wait until 5;
  169. Direct_Connect:
  170.     exit %Success;
  171.  
  172. Modem_Failure:
  173.     FailStr = "Dialing unsuccessful, check phone number";
  174.     wait until WaitTime;
  175.     goto End_Phone_Loop;
  176.  
  177. No_Dial_Tone:
  178.     FailStr = "No Dial";
  179.     goto Exit_Failure;
  180.  
  181. Dial_Complete:
  182.     MsgStr = "Dialed " & %Phone & ", awaiting answer";
  183.     show MsgStr;
  184.     goto Start_Phone_Loop;
  185.  
  186. Line_Busy:
  187.     FailStr = "Number is busy";
  188.     wait until 2 * WaitTime;
  189.     send %CR;
  190.  
  191.     wait
  192.         %mdm_Success    goto End_Line_Busy,
  193.         %mdm_Failure    goto End_Line_Busy,
  194.         "No Dial"    goto End_Line_Busy,
  195.         "Dial Complete" goto End_Line_Busy,
  196.         "Busy"        goto End_Line_Busy,
  197.         "Ring"        goto End_Line_Busy
  198.     until 56;
  199.  
  200. End_Line_Busy:
  201.     wait until WaitTime;
  202.     goto End_Phone_Loop;
  203.  
  204. Remote_Ring:
  205.     if RingCount <= RingLimit goto Show_Ringing;
  206.  
  207.     FailStr = "No answer";
  208.     goto End_Phone_Loop;
  209.  
  210. Show_Ringing:
  211.     MsgStr = %Phone & " is ringing, awaiting answer";
  212.     show MsgStr;
  213.     goto Start_Phone_Loop;
  214.  
  215. End_Phone_Loop:
  216.     MsgStr = FailStr & ", redialing " & %Phone;
  217.     count = count + 1;
  218.     goto Dial_Phone;
  219.  
  220. Phone_Cancelled:
  221.     gosub Hangup_Before_Connect;
  222.     exit Result;
  223.  
  224. Phone_Failed:
  225.     if FailStr <> "" goto Exit_Fatal;
  226.     FailStr = "Dialing failed";
  227.  
  228. Exit_Fatal:
  229.     define %FailureMsg = FailStr;
  230.     exit %Fatal;
  231.  
  232. Exit_Failure:
  233.     define %FailureMsg = FailStr;
  234.     exit %Failure;
  235.